package modules.gameCommunication;

import common.GameServer;

public class PacketParser {

    private DataCenter dataCenter;

    public PacketParser() {
    }

    public PacketParser(DataCenter pDatCent) {
        dataCenter = pDatCent;
    }

    public void parsePacket(String packet) {
        GameServer.writeLine("packet : " + packet);
        //If not allowed packet when not auth
        if (!dataCenter.getIsAuth() && !packet.substring(0, 2).equals("AT")) {
            dataCenter.setRunning(false);
            GameServer.writeLine("Client from " + dataCenter.getIP() + " sent a unallowed packet before HelloGame Packet: Client kick");
            return;
        }

        switch (packet.charAt(0)) {
            case 'A'://Account
                dataCenter.getPckData().parseAccountPacket(packet);
                break;

            case 'B'://Basics
                dataCenter.getPckData().parseBasicsPacket(packet);
                break;

            case 'c'://Chat
                dataCenter.getPckData().parseChatPacket(packet);
                break;

            case 'C'://Conquest
                dataCenter.getPckData().parseConquestPacket(packet);
                break;

            case 'D'://Dialog
                dataCenter.getPckData().parseDialogPacket(packet);
                break;

            case 'd'://Documents
                dataCenter.getPckData().parseDocumentsPacket(packet);
                break;

            case 'e'://Emotes
                dataCenter.getPckData().parseEmotesPacket(packet);
                break;

            case 'i'://Enemies
                dataCenter.getPckData().parseEnemiesPacket(packet);
                break;

            case 'E'://Exchange
                dataCenter.getPckData().parseExchangePacket(packet);
                break;

            case 'f'://Fights
                dataCenter.getPckData().parseFightsPacket(packet);
                break;

            case 'F'://Friends
                dataCenter.getPckData().parseFriendsPacket(packet);
                break;

            case 'G'://Game & GameActions
                dataCenter.getPckData().parseGamePacket(packet);

                break;

            case 'g'://Guild
                dataCenter.getPckData().parseGuildPacket(packet);
                break;

            case 'h'://Houses
                dataCenter.getPckData().parseHousesPacket(packet);
                break;

            case 'I'://Infos
                dataCenter.getPckData().parseInfosPacket(packet);
                break;

            case 'O'://Items
                dataCenter.getPckData().parseItemsPacket(packet);
                break;

            case 'J'://Job
                dataCenter.getPckData().parseJobPacket(packet);
                break;

            case 'K'://Key
                dataCenter.getPckData().parseKeyPacket(packet);
                break;

            case 'R'://Mount
                dataCenter.getPckData().parseMountPacket(packet);
                break;

            case 'P'://Party
                dataCenter.getPckData().parsePartyPacket(packet);
                break;

            case 'Q'://Quests
                dataCenter.getPckData().parseQuestsPacket(packet);
                break;

            case 'S'://Spells
                dataCenter.getPckData().parseSpellsPacket(packet);
                break;

            case 'W'://Subway & Waypoints
                dataCenter.getPckData().parseWaypointsPacket(packet);
                break;

            case 'T'://Tutorial
                dataCenter.getPckData().parseTutorialPacket(packet);
                break;

            default:
                dataCenter.setRunning(false);
                GameServer.writeLine("Client from " + dataCenter.getIP() + " send unknown packet");
                break;
        }
    }
}